﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Management;
using System.Collections;

namespace RollBackLib.src.utils
{
    /**
     * Handle one of the drive
     */
    public class DriveHandler
    {
        private ManagementObject mo;
        private static ArrayList driveList = new ArrayList();

        public DriveHandler(ManagementObject mo)
        {
            this.mo = mo;
        }

        public String GetName( )
        {
            return mo["Name"].ToString();
        }

        /**
         * Get fresh list of drive handlers
         */
        public static ArrayList GetDriveHandlers( ) 
        {
            lock (driveList) {
                driveList.Clear();
                RollBackLib.src.sys.Sysutils sysutils = RollBackLib.src.sys.Sysutils.Instance;
                ManagementObjectCollection c = sysutils.getDrives();
                foreach (ManagementObject i in c) {
                    var h = new DriveHandler(i);
                    driveList.Add(h);
                }
            }
            return driveList;
        }

        public static bool IsADrive(string dir) {
            string d = dir.Replace(":\\", ":");
            lock (driveList) {
                foreach (DriveHandler h in driveList) {
                    if (h.GetName() == d)
                        return true;
                }
            }
            return false;
        }
    }
}
